Scoped Extension Methods in Dynamically-Typed Languages
نویسندگان
چکیده
Context. An extension method is a method declared in a package other than the package of its host class. Thanks to extension methods, developers can adapt to their needs classes they do not own: adding methods to core classes is a typical use case. This is particularly useful for adapting software and therefore to increase reusability. Inquiry. In most dynamically-typed languages, extension methods are globally visible. Because any developer can define extension methods for any class, naming conflicts ocur: if two developers define an extension method with the same signature in the same class, only one extension method is visible and overwrites the other. Similarly, if two developers each define an extension method with the same name in a class hierarchy, one overrides the other. To avoid such “accidental overrides”, some dynamically-typed languages limit the visibility of an extension method to a particular scope. However, their semantics have not been fully described and compared. In addition, these solutions typically rely on a dedicated and slow method lookup algorithm to resolve conflicts at runtime. Approach. In this article, we present a formalization of the underlying models of Ruby refinements, Groovy categories, Classboxes, and Method Shelters that are scoping extension method solutions in dynamicallytyped languages. Knowledge. Our formal framework allows us to objectively compare and analyze the shortcomings of the studied solutions and other different approaches such as MultiJava. In addition, language designers can use our formal framework to determine which mechanism has less risk of “accidental overrides”. Grounding.Our comparison and analysis of existing solutions is grounded because it is based on denotational semantics formalizations. Importance. Extension methods are widely used in programming languages that support them, especially dynamically-typed languages such as Pharo, Ruby or Python. However, without a carefully designed mechanism, this feature can cause insidious hidden bugs or can be voluntarily used to gain access to protected operations, violate encapsulation or break fundamental invariants. ACM CCS 2012 Software and its engineering→ Modules / packages; Theory of computation→ Formalisms;
منابع مشابه
Dynamically Scoped Functions for Runtime Modification
The importance of lexically scoped variable and function definitions is acknowledged in almost all programming languages. However, there are only few languages that provide dynamically scoped variables as well in spite of their usefulness. Furthermore, dynamically scoped functions have been largely dismissed. This paper provides a new perspective on dynamically scoped functions and sketches a d...
متن کاملGeneric Description of Well-Scoped, Well-Typed Syntaxes
We adapt the technique of type-generic programming via descriptions pointing into a universe to the domain of typed languages with binders and variables, implementing a notion of syntax-generic programming in a dependently typed programming language. We present an Agda library implementation of type-preserving renaming and substitution (including proofs about their behaviour) “once and for all”...
متن کاملNotes on Futures 15 - 312 : Foundations of Programming Languages
In this lecture we first examine a technique to specify the operational semantics for lazy evaluation. This is an implementation technique for a call-by-name semantics that avoids re-evaluating expressions multiple times by memoizing the result of the first evaluation. Then we use a similar technique to specify the meaning of futures, a construct that introduces parallelism into evaluation. Fut...
متن کاملLecture Notes on Futures 15-312: Foundations of Programming Languages
In this lecture we first examine a technique to specify the operational semantics for lazy evaluation. This is an implementation technique for a call-by-name semantics that avoids re-evaluating expressions multiple times by memoizing the result of the first evaluation. Then we use a similar technique to specify the meaning of futures, a construct that introduces parallelism into evaluation. Fut...
متن کاملType-directed weaving of aspects for polymorphically typed functional languages
Incorporating aspect-oriented paradigm to a polymorphically typed functional language enables the declaration of type-scoped advice, in which the effect of an aspect can be harnessed by introducing possibly polymorphic type constraints to the aspect. The amalgamation of aspect orientation and functional programming enables quick behavioral adaption of functions, clear separation of concerns and...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- Programming Journal
دوره 2 شماره
صفحات -
تاریخ انتشار 2018